import { Logger } from "../../engine/utils/Logger";


export enum MusicItem_Side {
    Up = 0,
    Down = 1,
    Left = 2,
    Right = 3,
}



export enum MusicItem_Type {
    PressNode = 0,
    Arrow = 1,
    Line = 2

}

export default class MusicItem {

    public static maxId: number = 1;

    public id: number = 0;
    public appeartTime: number = 1; //出现时间
    public type: number = 1; //类型
    public col: number = 0; //列
    public distance: number = 0;
    public side: number;
    public childItem: MusicItem;
    public parentItem:MusicItem;

    public node: cc.Node = null;


    public initP: cc.Vec2 = cc.v2(0, 0);
    public targetP: cc.Vec2 = cc.v2(0, 0);

    /**
     * @param appeartTime  出现时间(单位帧)
     * @param type item类型
     * @param col 所在列
     * @param side 方向
     * @param distance 长度
     */
    constructor(appeartTime: number, type: number, col: number, side: number = MusicItem_Side.Right, distance: number = 0, chilItem: MusicItem = null) {
        this.id = MusicItem.maxId;
        MusicItem.maxId++;
        this.appeartTime = appeartTime;
        this.type = type;
        this.col = col;
        this.side = side;
        this.distance = distance;
        this.childItem = chilItem;
    }

    /**
     * @param appeartTime  出现时间(单位帧)
     * @param type item类型
     * @param col 所在列
     * @param side 方向
     * @param distance 长度
     */
    public static create(appeartTime: number, type: number, col: number, side: number = MusicItem_Side.Right, distance: number = 0, childItem: MusicItem = null) {
        return new MusicItem(appeartTime, type, col, side, distance, childItem);
    }

    public static getRotationBySide(side: number) {
        if (side == MusicItem_Side.Up) {
            return 270;
        } else if (side == MusicItem_Side.Down) {
            return 90;
        } else if (side == MusicItem_Side.Left) {
            return 0;
        } else if (side == MusicItem_Side.Right) {
            return 180
        } else {
            Logger.warn("getRotationBySide error=", side)
        }
    }

    public static getRotationBySideAndCol(side: number, col: number) {
        let rotConfig: Array<Array<number>> = [
            [232, 258, 275, 300],
            [52, 78, 95, 120],
        ];
        if (side == MusicItem_Side.Up) {
            return rotConfig[0][col];
        } else if (side == MusicItem_Side.Down) {
            return rotConfig[1][col]
        } else if (side == MusicItem_Side.Left) {
            return 0;
        } else if (side == MusicItem_Side.Right) {
            return 180
        } else {
            Logger.warn("getRotationBySide error=", side)
        }
    }
}